<?php

class PaginatorController extends ApplicationController {
	protected $AppName = "paginator";
	
	function init(){
		return $this;
	}
	
	function generatePaginator($total, $on_page, $current_position){
		$numberPages = ceil($total/$on_page);
		
		$currentPage = ceil($current_position/$on_page);
		
		$Paginator = array($currentPage => $currentPage);
		
		$continue_before = true;
		$page_before = $currentPage;
		
		$continue_after = true;
		$page_after = $currentPage;
		
		while (($page_after || $page_before) && count($Paginator) < $numberPages) {
			if($page_before > 1 && $continue_before == true){
				$page_before--;
				$Paginator[$page_before] = $page_before;
			}			
			else {
				$continue_before = false;
			}
			
			if($page_after < $numberPages && $continue_after == true){
				$page_after++;
				$Paginator[$page_after] = $page_after;
			}
			else {
				$continue_after = false;
			}
		}
			
		ksort($Paginator);
		return $Paginator;
	}
}

?>